package com.lonely.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.api.R;
import com.lonely.system.domain.dto.tag.SysTagPageQueryDto;
import com.lonely.system.domain.dto.tag.SysTagSubmitDto;
import com.lonely.system.domain.vo.system.tag.SysTagPageQueryVo;
import com.lonely.system.domain.vo.system.tag.TagSelectVo;
import com.lonely.system.service.ISysTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 黄志标
 * @date: 2025/6/17 17:07
 * @description: 标签管理请求处理器
 */
@RestController
@RequestMapping("/systemManage/tag")
@Api(tags = "系统管理/标签管理")
public class SysTagController {

    @Autowired
    private ISysTagService sysTagService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
//    @SaCheckPermission("system:tag:page")
    public R<Page<SysTagPageQueryVo>> page(@RequestBody SysTagPageQueryDto queryDto) {
        return R.data(this.sysTagService.page(queryDto));
    }


    /**
     * 创建标签
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "创建标签")
    @SaCheckPermission("system:tag:create")
    public R<Boolean> create(@RequestBody @Validated SysTagSubmitDto submitDto) {
        this.sysTagService.create(submitDto);
        return R.status(true);
    }


    /**
     * 编辑标签
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "编辑标签")
    @SaCheckPermission("system:tag:edit")
    public R<Boolean> edit(@RequestBody @Validated SysTagSubmitDto submitDto) {
        this.sysTagService.edit(submitDto);
        return R.status(true);
    }

    /**
     * 启用标签
     *
     * @param id
     * @return
     */
    @GetMapping("/enabled/{id}")
    @ApiOperation(value = "启用标签")
    @SaCheckPermission("system:tag:enabled")
    public R<Boolean> enabled(@PathVariable("id") Long id) {
        this.sysTagService.enabled(id);
        return R.status(true);
    }

    /**
     * 禁用标签
     *
     * @param id
     * @return
     */
    @GetMapping("/disable/{id}")
    @ApiOperation(value = "禁用标签")
    @SaCheckPermission("system:tag:disable")
    public R<Boolean> disable(@PathVariable("id") Long id) {
        this.sysTagService.disable(id);
        return R.status(true);
    }

    /**
     * 获取标签下拉列表
     *
     * @return
     */
    @GetMapping("/getTagSelect")
    @ApiOperation(value = "获取标签下拉列表")
    public R<List<TagSelectVo>> getTagSelect() {
        return R.data(this.sysTagService.getTagSelect());
    }
}
